home *** CD-ROM | disk | FTP | other *** search
- { This unit establishes a thread to monitor port status }
- unit CommStatus;
-
- interface
-
- uses
- Windows, Classes, Graphics, ExtCtrls, TAPI;
-
- type
- TCommStatus = class(TThread)
- private
- { Private declarations }
- protected
- procedure Execute; override;
- end;
-
- implementation
-
- uses
- Tapiu_2;
-
- const
- off = 0;
- red = 1;
- yellow = 2;
- green = 3;
-
- { Important: Methods and properties of objects in VCL can only be used in a
- method called using Synchronize, for example,
-
- Synchronize(UpdateCaption);
-
- and UpdateCaption could look like,
-
- procedure TCommStatus.UpdateCaption;
- begin
- Form1.Caption := 'Updated in a thread';
- end; }
-
- { TCommStatus }
-
- procedure TCommStatus.Execute;
- var
- dwEvent: DWord;
- dwStatus: DWord;
- begin
- dwEvent := 0;
- SetCommMask(FPort, EV_DSR or EV_CTS or SETDTR);
- repeat
- WaitCommEvent(FPort, dwEvent, nil);
- GetCommModemStatus(FPort, dwStatus);
- case dwEvent of
- EV_DSR: Form1.SetBitmap(Form1.DSR, green);
- SETDTR: Form1.SetBitmap(Form1.DTR, green);
- EV_CTS: Form1.SetBitmap(Form1.CTS, green);
- end;
- // Form1.SetBitmap(Form1.AA, green);
- until Terminated;
- end;
-
- end.
-